<?php
/**
 * Created by PhpStorm.
 * User: dolia
 * Date: 2016/4/11
 * Time: 9:18
 */

namespace App\Http\Controllers\Api\V1;

use App\Exceptions\Api\ApiDoneErrorException;
use App\Exceptions\Api\ApiInputErrorException;
use App\Exceptions\Api\ApiRsaEecryptErrorException;
use App\Exceptions\Api\ApiUserNotLoginErrorException;
use App\Exceptions\Api\ApiValidateErrorException;
use App\Http\Controllers\Controller;
use App\Interfaces\ActivityService;

class ActivityController extends Controller{

    /**
     * @api {post} /activity/get_recommend_activity 获取推荐活动
     * @apiName Activity/getRecommendActivity
     * @apiGroup Activity
     * @apiDescription 获取推荐活动
     * @apiSuccess {Object[]}  Object   推荐活动信息
     * @apiSuccess {int} Object.id 活动ID
     * @apiSuccess {string} Object.name 活动名称
     * @apiSuccess {int} Object.is_recommend 是否推荐
     * @apiSuccess {string} Object.description 活动描述
     * @apiSuccess {string} Object.template 模板
     * @apiSuccess {int} Object.add_time 添加时间
     * @apiSuccess {string} Object.identification 活动页标识
     * @apiSuccess {int} Object.sort_order 排序
     * @apiSuccess {string} Object.activity_thumb 活动缩略图
     * @apiSuccess {string} Object.bg_img 背景图片
     * @apiSuccess {string} Object.bg_color 背景颜色
     * @apiSuccess {int} Object.bg_margin_top 背景图片距离顶部高度
     * @apiSuccess {string} Object.tit_img 标题图片
     * @apiSuccess {int} Object.tit_width 标题图片宽
     * @apiSuccess {int} Object.tit_height 标题图片高
     * @apiSuccess {int} Object.tit_line_height 标题行高
     * @apiSuccess {int} Object.tit_font_size 标题字体
     * @apiSuccess {string} Object.tit_font_color 标题字体颜色
     * @apiSuccess {string} Object.tit_position 标题位置
     * @apiSuccess {string} Object.sidebar_bg_color 导航背景色
     * @apiSuccess {string} Object.sidebar_hover_color 导航鼠标悬浮颜色
     * @apiSuccess {int} Object.sidebar_top 导航距离顶部距离
     * @apiSuccess {int} Object.sidebar_left 导航距离左边距离
     * @apiSuccess {int} Object.sidebar_line_height 导航行高
     * @apiSuccess {int} Object.sidebar_font_size 导航字号
     * @apiSuccess {string} Object.sidebar_font_color 导航字体颜色
     * @apiSuccess {string} Object.mobile_activity_thumb 活动缩略图地址
     * @apiSuccess {string} Object.mobile_bg_img 背景图片地址
     * @apiSuccess {string} Object.mobile_tit_img 标题图片地址
     * @apiSuccess {string} Object.activity_url 活动url
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
    [
        {
            "id": 2,
            "name": "美妆个护",
            "is_recommend": 1,
            "description": "经典时尚，引领潮流",
            "template": "",
            "add_time": "2015-12-24 15:56:05",
            "identification": "index_4",
            "sort_order": 4,
            "activity_thumb": "60ae28709f53e8db6645d1f5490be958",
            "bg_img": "a30d21755b41452ab9839ad62d373f32",
            "bg_color": "fff",
            "bg_margin_top": 430,
            "tit_img": "9c56c81a20549568a6e4f25e735d781d",
            "tit_width": 0,
            "tit_height": 80,
            "tit_line_height": 70,
            "tit_font_size": 28,
            "tit_font_color": "fff",
            "tit_position": "center",
            "sidebar_bg_color": "434248",
            "sidebar_hover_color": "2b2b30",
            "sidebar_top": 470,
            "sidebar_left": 540,
            "sidebar_line_height": 18,
            "sidebar_font_size": 14,
            "sidebar_font_color": "fff"，
            "mobile_activity_thumb": "http://dolia.img-cn-hangzhou.aliyuncs.com/60ae28709f53e8db6645d1f5490be958.jpg",
            "mobile_bg_img": "http://dolia.img-cn-hangzhou.aliyuncs.com/a30d21755b41452ab9839ad62d373f32.jpg",
            "mobile_tit_img": "http://dolia.img-cn-hangzhou.aliyuncs.com/9c56c81a20549568a6e4f25e735d781d.png",
            "activity_url": "m.afuyigou.cn/activity/index_4"
        }
    ]
     * @apiErrorExample Error-Response 01:
     * HTTP/1.1 202 Accepted
    {
    "message": "没有推荐活动"
    }
     */
    public function getRecommendActivity(ActivityService $activityService){

        $recommendActivitys = $activityService->getRecommendActivity()->toArray();
        //config('domain.mobile')env('MOBIL_DOMAIN')
        $recommendActivityArr = array();
        foreach ($recommendActivitys as $key=>$value) {
            $recommendActivityArr[$key] = $value;
            $recommendActivityArr[$key]['activity_url'] =config('domain.mobile') ."/activity/".$value['id'];
        }

        if($recommendActivityArr){
            return response()->json($recommendActivityArr);
        }else{
            throw new ApiDoneErrorException('没有推荐活动');
        }
    }

    /**
     * @api {post} /activity/get_activity/{activity_id} 根据活动ID获取活动信息
     * @apiName Activity/getActivity
     * @apiGroup Activity
     * @apiDescription 根据活动ID获取活动信息
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
    {
    "id": 2,
    "name": "美妆个护",
    "is_recommend": 1,
    "description": "经典时尚，引领潮流",
    "template": "",
    "add_time": "2015-12-24 15:56:05",
    "identification": "index_4",
    "sort_order": 4,
    "activity_thumb": "60ae28709f53e8db6645d1f5490be958",
    "bg_img": "a30d21755b41452ab9839ad62d373f32",
    "bg_color": "fff",
    "bg_margin_top": 430,
    "tit_img": "9c56c81a20549568a6e4f25e735d781d",
    "tit_width": 0,
    "tit_height": 80,
    "tit_line_height": 70,
    "tit_font_size": 28,
    "tit_font_color": "fff",
    "tit_position": "center",
    "sidebar_bg_color": "434248",
    "sidebar_hover_color": "2b2b30",
    "sidebar_top": 470,
    "sidebar_left": 540,
    "sidebar_line_height": 18,
    "sidebar_font_size": 14,
    "sidebar_font_color": "fff"，
    "mobile_activity_thumb": "http://dolia.img-cn-hangzhou.aliyuncs.com/60ae28709f53e8db6645d1f5490be958.jpg",
    "mobile_bg_img": "http://dolia.img-cn-hangzhou.aliyuncs.com/a30d21755b41452ab9839ad62d373f32.jpg",
    "mobile_tit_img": "http://dolia.img-cn-hangzhou.aliyuncs.com/9c56c81a20549568a6e4f25e735d781d.png"
    }
     * @apiErrorExample Error-Response 01:
     * HTTP/1.1 202 Accepted
    {
    "message": "该活动不存在"
    }
     */
    public function getActivity($activity_id,ActivityService $activityService){
        $activity = $activityService->getActivity($activity_id);
        if($activity){
            return response()->json($activity);
        }else{
            throw new ApiDoneErrorException('该活动不存在');
        }
    }


    public function getActivityByIdentification($identification,ActivityService $activityService){
        $activity = $activityService->getActivityByIdentification($identification);
        if($activity){
            return response()->json($activity);
        }else{
            throw new ApiDoneErrorException('该活动不存在');
        }
    }

    /**
     * @api {post} /activity/get_activity_cat_goods/{activity_cat_id} 获取活动专题商品信息
     * @apiName Activity/getActivityGoods
     * @apiGroup Activity
     * @apiDescription 获取活动专题商品信息
     * @apiParam {string} activity_cat_id  活动专题ID
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
    [
    {
    "id": 56,
    "activity_cat_id": 3,
    "goods_id": 1339,
    "sort_order": 100,
    "goods_thumb": "0679fcfb50d4b6dde1b8d3ea56ef4ea2",
    "goods_name": "雅漾1",
    "goods_pet_name": "雅漾1",
    "market_price": "22.00",
    "shop_price": "20.00",
    "is_on_sale": 1，
    "mobile_goods_thumb": "http://dolia.img-cn-hangzhou.aliyuncs.com/0679fcfb50d4b6dde1b8d3ea56ef4ea2.jpg"
    }
    ]
     * @apiErrorExample Error-Response 01:
     * HTTP/1.1 202 Accepted
    {
    "message": "该活动下没有活动商品"
    }
     */
    public function getActivityGoods($activity_cat_id,ActivityService $activityService){
        $activityGoods = $activityService->getActivityGoods($activity_cat_id);
        if($activityGoods){
            return response()->json($activityGoods);
        }else{
            throw new ApiDoneErrorException('该活动下没有活动商品');
        }
    }

} 